package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.StoreService;
import com.tarena.lbs.pojo.basic.param.StoreParam;
import com.tarena.lbs.pojo.basic.param.UserLocationParam;
import com.tarena.lbs.pojo.basic.query.AreaStoreQuery;
import com.tarena.lbs.pojo.basic.query.StoreQuery;
import com.tarena.lbs.pojo.basic.vo.StoreVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 店铺相关功能接口
 */
@RestController
@Slf4j
public class StoreController {
    @Autowired
    private StoreService storeService;
    //查询现有店铺 分页列表数据
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query)
        throws BusinessException{
        return new Result<>(storeService.pageList(query));
    }
    //店铺新增
    @PostMapping("/admin/basic/store/add")
    public Result<Void> addStore(@RequestBody StoreParam storeParam)
    throws BusinessException{
        storeService.addStore(storeParam);
        return Result.success();
    }
    //根据区域id集合查询某个商家店铺
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getCityStore(
            @RequestBody AreaStoreQuery query)
        throws BusinessException{
        return new Result<>(storeService.getCityStore(query));
    }
    //小程序定位上报
    @PostMapping("/basic/store/location")
    public Result<Void> storeLocation(@RequestBody UserLocationParam param)
    throws BusinessException{
        storeService.location(param);
        return Result.success();
    }
}
